package com.boot.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @TableName user
 * create table user
 * (
 * id       int auto_increment
 * primary key,
 * username varchar(30)   not null,
 * age      int default 0 null,
 * nickname varchar(30)   null,
 * password varchar(50)   null,
 * enable   int           null
 * );
 * <p>
 * CREATE TABLE roles (
 * id int PRIMARY KEY,
 * name VARCHAR(20) UNIQUE
 * );
 * create table user_roles (
 * user_id int,
 * role_id int,
 * primary key (user_id, role_id),
 * foreign key (user_id) references user(id),
 * foreign key (role_id) references  roles(id)
 * )
 */
@TableName(value = "user")
@Data
@AllArgsConstructor
public class User {
    @Id
    @TableId(type = IdType.AUTO)
    private Long id;

    private String username;
    private String password;

    private Integer age;
    private String nickname;
    private Integer enable;

    public User() {
        setDefault();
    }

    public void setDefault() {
        age = 18;
        nickname = "工程师" + UUID.randomUUID().toString().substring(0, 5);
        enable = 1;
    }
}